<template>
  <svg
    :class="svgClass"
    aria-hidden="true"
    :style="`width:${size}px;height:${size}px;`"
  >
    <use :xlink:href="iconName" />
  </svg>
</template>

<script>
export default {
  name: "SvgIcon",
  props: {
    iconClass: {
      type: String,
      required: true,
    },
    className: {
      type: String,
      default: "",
    },
    // 传入svg大小 单位px
    size: {
      type: String,
      default: "18",
    },
  },
  computed: {
    iconName() {
      return `#icon-${this.iconClass}`;
    },
    svgClass() {
      if (this.className) {
        return "svg-icon " + this.className;
      } else {
        return "svg-icon";
      }
    },
  },
};
</script>

<style scoped>
.svg-icon {
  --size: 18px;
  width: var(--size);
  height: var(--size);
  fill: currentColor;
  overflow: hidden;
  fill: white;
  vertical-align: middle;
}
</style>
